package com.zeta.eduservice.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zeta.commonutils.R;
import com.zeta.eduservice.entity.EduTeacherClass;
import com.zeta.eduservice.service.EduTeacherClassService;

/**
 * <p>
 * 教师 班级中间表 前端控制器
 * </p>
 *
 * @author zeta
 * @since 2020-08-28
 */
@CrossOrigin
@RestController
@RequestMapping("/eduservice/edu_teacher_class")
public class EduTeacherClassController {

	@Autowired
	EduTeacherClassService TeacherClassService;
	
	@PostMapping("")
	public R add(@RequestBody EduTeacherClass teacherClass) {
		boolean save = TeacherClassService.save(teacherClass);
		if(save)
			return R.ok();
		else 
			return R.error();
	}
	@DeleteMapping("{id}")
	public R delete(@PathVariable String id) {
		boolean removeById = TeacherClassService.removeById(id);
		if(removeById)
			return R.ok();
		else 
			return R.error();
	}
	@GetMapping("/getByTeacher/{teacherId}")
	public R getByTeacherId(@PathVariable String teacherId ) {
		
		List<EduTeacherClass> list = TeacherClassService.findByTeacher(teacherId);
		return R.ok().data("classs",list);
		
	}
	@GetMapping("/getByclasss/{classsId}")
	public R getByClasssId(@PathVariable String classsId ) {
		QueryWrapper<EduTeacherClass> queryWrapper = new QueryWrapper<EduTeacherClass>();
		queryWrapper.eq("classs", classsId);
		List<EduTeacherClass> list = TeacherClassService.list(queryWrapper);
		return R.ok().data("classs",list);
		
	}
}

